﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCFTest.RioWCFServiceReference;
using System.ServiceModel;

namespace WCFTest
{
    public static class ServiceManager
    {

        private static string RioWCFEndPoint    = "http://localhost/RioWCFServices/RioWCFService.svc";
        private static string OpenTimeout = "10";
        private static string SendTimeout = "10";
        private static string ReceiveTimeout = "10";
        private static string LicenseKey = "123456";

        /// <summary>
        /// Provide custom proxy for RioWCFServices
        /// </summary>
        /// <returns></returns>
        public static WCFServiceClient GetRioWCFServiceClient()
        {
            string[] l_oHttpMode = RioWCFEndPoint.Split(':');
            BasicHttpBinding binding = new BasicHttpBinding(
                l_oHttpMode[0].Equals("https", StringComparison.InvariantCultureIgnoreCase)
                ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None);
            binding.MaxReceivedMessageSize = Int32.MaxValue;
            binding.MaxBufferSize = Int32.MaxValue;
            binding.ReceiveTimeout = new TimeSpan(0, Convert.ToInt32(ReceiveTimeout), 0);
            binding.SendTimeout = new TimeSpan(0, Convert.ToInt32(SendTimeout), 0);
            binding.OpenTimeout = new TimeSpan(0, Convert.ToInt32(OpenTimeout), 0);
            
            EndpointAddress e =  new EndpointAddress(new Uri(RioWCFEndPoint));
            
            return new WCFServiceClient(binding, e);
        }

        public static MessageRequest GetLicenseKey()
        {
            MessageRequest l_oMsgRequest = new MessageRequest();
            l_oMsgRequest.LicenseKey = LicenseKey;
            return l_oMsgRequest;
        }

   
    }
}
